<!DOCTYPE html>
<html lang="en" xml:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>我的预约</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/css/custom.form.css">
</head>
<body>
<!--数据与分页-->
<div class="user_table_div">
    <table class="layui-hide" id="user_table" lay-filter="user_table"></table>
</div>

</body>
<script src="/layui/layui.js"></script>
<script src="/js/core.util.js"></script>
<script type="text/html" id="tool">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    layui.use(['jquery', 'form', 'table', 'laypage', 'layer', 'laydate', 'tree', 'transfer'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var table = layui.table;
        var layer = layui.layer;
        var laydate = layui.laydate;

        /*分页参数*/
        var searchParam = {
            pageNum: 1,
            pageSize: 10,
            /*以下为多条件查询参数*/
            name: null
        }

        /*动态获取数据*/
        var reloadTreeTable = function () {
            CoreUtil.sendAjax("/health/reserve/record", searchParam, function (res) {

                //初始化渲染数据
                loadTable(res.list);
                if (res.list != null) {
                    loadTable(res.list);
                }
            }, "GET", false, function (res) {
                //用户列表接口无权限回调
                layer.msg("抱歉！您暂无获取用户列表的权限");
                var noAuthorityData = [];
                loadTable(noAuthorityData);
            });
        }
        //渲染table
        var loadTable = function (data) {
            //展示已知数据
            table.render({
                elem: '#user_table'
                // 这个 data 为数组数据，直接 放到 data 上即可。
                , data: data
                , even: true
                , toolbar: '#toolbar'
                , cols: [
                    [
                        {type: 'checkbox', fixed: 'left'},
                        {field: 'id', title: 'ID', width: 300, sort: true},
                        {field: 'departmentName', title: '科室名', width: 230},
                        {field: "doctorName", title: "医生名", width: 220},
                        {field: "patientName", title: "患者名", width: 220},
                        {
                            field: "startingTime", title: "开始时间", width: 250, templet: function
                                (item) {
                                return CoreUtil.formattime(item.startingTime);
                            }
                        },
                        {
                            field: 'endTime', title: '结束时间', width: 250, templet: function
                                (item) {
                                return CoreUtil.formattime(item.endTime);
                            }
                        },
                        {
                            field: 'status', title: '状态', width: 120, templet: function (item) {
                                if (item.status === 1) {
                                    return ' <input type="checkbox" lay-skin="switch" lay-text="已审核|未审核" checked disabled>';
                                }
                                if (item.status === 0) {
                                    return ' <input type="checkbox" lay-skin="switch" lay-text="已审核|未审核" disabled>';
                                }
                            }
                        },
                        {width: 300, toolbar: "#tool", title: '操作'}
                    ]
                ]
            });
        };
        reloadTreeTable();


        //执行查询
        $("#search").click(function () {
            searchParam.name = $("#name").val();
            searchParam.pageNum = 1;
            CoreUtil.sendAjax("/health/reserve/record", searchParam, function (res) {
                if (res.list != null) {
                    loadTable(res.list);
                }
            }, "GET", false, function (res) {
                //用户列表接口无权限回调
                layer.msg("抱歉！您暂无获取用户列表的权限");
                var noAuthorityData;
                noAuthorityData = [];
                loadTable(noAuthorityData);
            });
        });

        // 操作工具栏 点击赋予角色事件事件
        table.on('tool(user_table)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'del':
                    var userIds = [];
                    userIds.push(data.id);
                    tipDialog(userIds, data.name);
                    break;
            }
        });

        //删除前确认对话框
        var tipDialog = function (userIds, name) {
            layer.open({
                content: '确定要删除么?',
                yes: function (index, layero) {
                    layer.close(index); //如果设定了yes回调，需进行手工关闭
                    CoreUtil.sendAjax("/health/reserve/delete", JSON.stringify(userIds), function (res) {
                        layer.msg(res.msg);
                        $(".layui-laypage-btn").click();
                        reloadTreeTable();
                    }, "DELETE", false, function (res) {
                        //删除用户无权限
                        layer.msg("抱歉！您暂无删除用户的权限");
                    });
                }
            });
        };

        // 渲染时间
        laydate.render({
            elem: '.createTime'
            , position: 'static'
            , change: function (value, date) { //监听日期被切换
                lay('#testView').html(value);
            }
        });
    });
</script>
</html>

